import React from 'react'
import { createStackNavigator, createBottomTabNavigator } from 'react-navigation';
import PropTypes from 'prop-types';
import Icon from 'react-native-vector-icons/FontAwesome';
import Style from '../../utils/style/style'
//screen
import Home from '../home/Home'
import User from '../user/User'
import Login from '../login/Login'
import Purchase from '../purchase/Purchase'
import Sales from '../sales/Sales'
import Checks from '../checks/Checks'
import PurchaseDetail from '../purchase/PurchaseDetail';
import Warehouse from '../purchase/warehouse';
import SalesDetail from '../sales/SaleDetail';
import Delivery from '../sales/delivery';
import CheckDetail from '../checks/checkDetail';
import Result from '../checks/result';
import ResultSerials from '../checks/resultSerials';
import ChecksAdd from '../checks/add';
import BannerDetail from '../home/bannerDetail';

//tabNavigator
const tabNavigator = createBottomTabNavigator(
    {
        Home: Home,
        User: User
    },
    {
        navigationOptions: ({ navigation }) => ({
            tabBarIcon: ({ focused, tintColor }) => {
                const { routeName } = navigation.state;
                let iconName;
                if (routeName === 'Home') {
                    iconName = `desktop`;
                } else if (routeName === 'User') {
                    iconName = `user`;
                }
                return <Icon name={iconName} size={27} color={tintColor} />;
            },

        }),
        tabBarOptions: {
            activeTintColor: '#04BE02',
            inactiveTintColor: 'gray',
        },
    })

tabNavigator.navigationOptions = ({ navigation }) => {
    let title, headerStyle, headerTitleStyle; const focusedRouteName = navigation.state.routes[navigation.state.index].routeName;
    if (focusedRouteName === 'Home') { title = '工作台'; headerStyle = { height: 41, backgroundColor: '#f7f7fa' }; headerTitleStyle = { fontSize: 16, color: '#000' } }
    else if (focusedRouteName === 'User') { title = '我的'; headerStyle = { height: 41, backgroundColor: '#1aad19' }; headerTitleStyle = { fontSize: 16, color: '#fff' } } return { title, headerStyle, headerTitleStyle };
};

export default AppNavigator = createStackNavigator(
    {
        Index: tabNavigator,
        Login: Login,
        Purchase: Purchase,
        PurchaseDetail: PurchaseDetail,
        Warehouse: Warehouse,
        Sales: Sales,
        SalesDetail: SalesDetail,
        Delivery: Delivery,
        Checks: Checks,
        CheckDetail: CheckDetail,
        Result: Result,
        ResultSerials: ResultSerials,
        ChecksAdd: ChecksAdd,
        BannerDetail:BannerDetail,

    },
    {
        initialRouteName: 'Index',
        //屏幕之间共享的参数
        navigationOptions: {
            headerStyle: {
                height: 41,
                backgroundColor: '#f7f7fa',
            },
            headerTitleStyle: {
                fontSize: 16
            }
        }
    },
)

const defaultGetStateForAction = AppNavigator.router.getStateForAction;
AppNavigator.router.getStateForAction = (action, state) => {
    // if (action.type == 'Navigation/REPLACE' && action.routeName == 'CheckDetail') {
    //     const params = action.params;
    //      state.routes.pop();
    //      let routes = state.routes
    //     if (routes[routes.length - 1].routeName == 'Checks') {
    //         routes[routes.length - 1].params = params;
    //     }
    //     routes.push({routeName:'CheckDetail',params:params})
    //     return {
    //         ...state,
    //         routes,
    //     };
    // }
    return defaultGetStateForAction(action, state);
}